package com.youwe.dao.demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.youwe.interfaces.dao.demo.BookDao;
import com.youwe.model.demo.Book;

@Repository
public class BookDaoImpl implements BookDao {
	
	private static Map<String, Book> bookMap = new HashMap<String, Book>();
	
	static {
		Book book1 = new Book("one","《钢铁是怎么样炼成的》",10.21f);
		Book book2 = new Book("two","《狂人日记》",13.21f);
		Book book3 = new Book("three","《穷爸爸富爸爸》",43.21f);
		Book book4 = new Book("four","《爱》",55.21f);
		Book book5 = new Book("five","《教育指南》",21.21f);
		Book book6 = new Book("six","《家》",8.21f);
		Book book7 = new Book("seven","《朝花夕拾》",34.21f);
		bookMap.put(book1.getId(), book1);
		bookMap.put(book2.getId(), book2);
		bookMap.put(book3.getId(), book3);
		bookMap.put(book4.getId(), book4);
		bookMap.put(book5.getId(), book5);
		bookMap.put(book6.getId(), book6);
		bookMap.put(book7.getId(), book7);
	}

	public void addBook(Book book) {
		bookMap.put(book.getId(), book);
	}

	public Book getBook(Book book) {
		return bookMap.get(book.getId());
	}

	public List<Book> getAllBook() {
		List<Book> bookList = new ArrayList<Book>();
		Set<String> keys = bookMap.keySet();
		for(String key : keys) {
			bookList.add(bookMap.get(key));
		}
		return bookList;
	}

	
	
}
